home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / timer11.zip / ZTIMER.CPP < prev    next >
C/C++ Source or Header  |  1992-04-21  |  2KB  |  103 lines

  1. /****************************************************************************
  2. *
  3. *                           The Zen Timer Library
  4. *
  5. *                               From the book
  6. *                         "Zen of Assembly Language"
  7. *                            Volume 1, Knowledge
  8. *
  9. *                             by Michael Abrash
  10. *
  11. *                      Modifications by Kendall Bennett
  12. *
  13. * Filename:        $RCSfile: ztimer.cpp $
  14. * Version:        $Revision: 1.4 $
  15. *
  16. * Language:        C++ 2.1
  17. * Environment:    IBM PC (MS DOS)
  18. *
  19. * Description:    Non-inline member functions for the C++ class interface
  20. *                to the Zen Timer Library.
  21. *
  22. * $Id: ztimer.cpp 1.4 92/04/21 01:47:50 kjb release $
  23. *
  24. * Revision History:
  25. * -----------------
  26. *
  27. * $Log:    ztimer.cpp $
  28. * Revision 1.4  92/04/21  01:47:50  kjb
  29. * Fixed bug in display routine for ULZTimer.
  30. * Revision 1.3  92/04/21  01:19:54  kjb
  31. * Converted to memory model dependant library.
  32. * Revision 1.2  92/04/21  00:47:36  kjb
  33. * Fixed code to be memory model independant.
  34. * Revision 1.1  92/04/20  17:34:54  kjb
  35. * Initial revision
  36. ****************************************************************************/
  37.  
  38. #include <iostream.h>
  39. #include "ztimer.h"
  40.  
  41. /*----------------------------- Implementation ----------------------------*/
  42.  
  43. // Routine to stop the ultra long period timer. The timer resolution is low
  44. // enough to make this routine non-inline.
  45.  
  46. void ULZTimer::stop()
  47. {
  48.     _finish = ULZReadTime();
  49.     if (!overflow()) {
  50.         ulong newcount = _count + ULZElapsedTime(_start,_finish);
  51.         if (newcount < _count || newcount == 0xFFFFFFFF)
  52.             _overflow = true;
  53.         else
  54.             _count = newcount;
  55.         }
  56. }
  57.  
  58. // Member functions to output the timed count in seconds to a stream.
  59.  
  60. ostream& operator << (ostream& o,PZTimer& timer)
  61. {
  62.     if (!timer.overflow()) {
  63.         o << timer.count() / timer.resolution() << '.';
  64.         int width = o.width(6);
  65.         char fill = o.fill('0');
  66.         o << timer.count() % timer.resolution();
  67.         o.width(width);
  68.         o.fill(fill);
  69.         }
  70.     else
  71.         o << "overflow";
  72.     return o;
  73. }
  74.  
  75. ostream& operator << (ostream& o,LZTimer& timer)
  76. {
  77.     if (!timer.overflow()) {
  78.         o << timer.count() / timer.resolution() << '.';
  79.         int width = o.width(6);
  80.         char fill = o.fill('0');
  81.         o << timer.count() % timer.resolution();
  82.         o.width(width);
  83.         o.fill(fill);
  84.         }
  85.     else
  86.         o << "overflow";
  87.     return o;
  88. }
  89.  
  90. ostream& operator << (ostream& o,ULZTimer& timer)
  91. {
  92.     if (!timer.overflow())
  93.         o << timer.count() / timer.resolution() << '.'
  94.           << timer.count() % timer.resolution();
  95.     else
  96.         o << "overflow";
  97.     return o;
  98. }
  99.